/* 
通过axios建立的服务，调用get/post的请求方法
*/

import request from '@/untils/request'

//登录接口
export const getLogin = (info) => {
    return request.post("user/login", info)
}


//用户信息接口
export const getUserInfo = (info) => {
    return request.get("user/getUserInfo")
}

//注册校验接口
export const registerValidate = (username) => {
    return request({
        method: "post",
        url: "user/checkUserName",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
        },
        data: `username=${username}`
    })
}

//用户注册
export const registerApi = (user) => {
    return request.post("user/register", user)
}

//分页带条件查询新闻
export const getFindNewsPageInfo = (info) => {
    return request.post("portal/findNewsPage", info)
}

//获取新闻分类列表
export const getFindAllTypes = () => {
    return request.get("/portal/findAllTypes")
}

//删除新闻
export const removeNewsByHid = (hid) =>{
    return request({
        method: "delete",
        url: "headline/removeByHid",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
        },
        data: `hid=${hid}`
    })
}

//获取新闻的内容
export const getShowNewsDetail = (hid)=>{
    return request({
        method: "post",
        url: "portal/showHeadlineDetail",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
        },
        data: `hid=${hid}`
    })
}

// 通过hid查询新闻，显示到修改页面
export const getFindHeadlineByHid = (hid)=>{
    return request({
        method: "post",
        url: "headline/findHeadlineByHid",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
        },
        data: `hid=${hid}`
    })
}

// 来判断用户登录信息是否过期
export const isUserOverdue = () =>{
    return request.get("user/checkLogin")
}

// 修改新闻
export const saveOrAddNews = (news) =>{
    return request.post("headline/update",news)
}
// 发布新闻
export const issueNews = (news) =>{
    return request.post("headline/publish",news)
}